﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SwingJoint : CombinableItem
{/// <summary>
/// 新属性
/// </summary>
    public SwingJointField NewSetting;
    public override ItemField ItemFieldSetting
    {
        get => NewSetting;
        set => NewSetting = value as SwingJointField;
    }
    public override void DownloadInstanceField(object args)
    {
        base.DownloadInstanceField(args);
        var tp = args as SwingJointField;
        downJointAngle = tp.JointAngle;
    }
    public float downJointAngle
    {
        get
        {
            if ((ItemFieldSetting as CombinableItemField).IsFliped)
                return -downJoint.localEulerAngles.z;
            else return downJoint.localEulerAngles.z;
        }
        set
        {
            downJoint.transform.localEulerAngles = new Vector3(0, 0, (ItemFieldSetting as CombinableItemField).IsFliped ? -value : value);
        }
    }

    public override ItemField UploadInstanceField()
    {
        ItemFieldSetting= base.UploadInstanceField();
        (ItemFieldSetting as SwingJointField).JointAngle = downJointAngle;
        return ItemFieldSetting;
    }
    Transform downJoint;
    public override void OnAwake()
    {
        base.OnAwake();
        downJoint = transform.Find("Collider").Find("DownJoint");
        sprite.gameObject.SetActive(false);
    }
}
[System.Serializable]
public class SwingJointField : CombinableItemField
{
    [HideInInspector]
    public float JointAngle = 0;
    public override void ClearWhenToBench()
    {
        base.ClearWhenToBench();
        JointAngle = 0;
    }
}
